package com.qsmx.store.app.main.system;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.qsmx.store.app.R;
import com.qsmx.store.app.R2;
import com.qsmx.store.app.main.mem.MemCardSaleSuitDelegate;
import com.qsmx.store.app.main.mem.adapter.LeftAdapter;
import com.qsmx.store.app.main.mem.entity.LeftTitleEntity;
import com.qsmx.store.core.delegates.AtmosDelegate;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class SystemSetHomeDelegate extends AtmosDelegate {
    LeftAdapter mAdapter;
    List<LeftTitleEntity.LeftTitleList> mList = new ArrayList<>();

    @BindView(R2.id.rlv_left)
    RecyclerView rlvMemCardLeft = null;

    @Override
    public Object setLayout() {
        return R.layout.delegate_home_content;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {

        getSupportDelegate().loadRootFragment(R.id.delegate_container, new SystemCoinAddAndCleanDelegate());

        initData();
        initView();

    }

    private void initView() {
        mAdapter = new LeftAdapter(getContext());
        mAdapter.setData(mList);
        LinearLayoutManager manager = new LinearLayoutManager(getContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);

        rlvMemCardLeft.setLayoutManager(manager);
        rlvMemCardLeft.setAdapter(mAdapter);

        mAdapter.setonItemClickListener(new LeftAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {

                if (position == 0) {
                    getSupportDelegate().replaceChildFragment(new SystemCoinAddAndCleanDelegate(), false);
                }
//                else if (position == 1) {
//                    getSupportDelegate().replaceChildFragment(new MemCardBackDelegate(), false);
//                } else if (position == 2) {
//                    getSupportDelegate().replaceChildFragment(new MemCardCurrentDelegate(), false);
//                } else if (position == 3) {
//                    getSupportDelegate().replaceChildFragment(new MemCardManagerDelegate(), false);
//                } else if (position == 4) {
//                    getSupportDelegate().replaceChildFragment(new MemCardPropertyDelegate(), false);
//                } else if (position == 5) {
//                    getSupportDelegate().replaceChildFragment(new MemCardPropertySearchDelegate(), false);
//                }

                for (LeftTitleEntity.LeftTitleList data : mList) {
                    data.setSelect(false);
                }

                mList.get(position).setSelect(true);
                mAdapter.notifyDataSetChanged();
            }
        });

    }

    private void initData() {

        LeftTitleEntity.LeftTitleList data = new LeftTitleEntity().new LeftTitleList();
        LeftTitleEntity.LeftTitleList data1 = new LeftTitleEntity().new LeftTitleList();
        LeftTitleEntity.LeftTitleList data2 = new LeftTitleEntity().new LeftTitleList();
        LeftTitleEntity.LeftTitleList data3 = new LeftTitleEntity().new LeftTitleList();
        LeftTitleEntity.LeftTitleList data4 = new LeftTitleEntity().new LeftTitleList();

        data.setTitle("售币机安装/回收");
        data.setIcon(R.mipmap.icon_card_sale);
        data.setSelect(true);

        data1.setTitle("服务器检测");
        data1.setIcon(R.mipmap.icon_card_continues);
        data1.setSelect(false);

        data2.setTitle("读卡器");
        data2.setIcon(R.mipmap.icon_card_turn);
        data2.setSelect(false);

        data3.setTitle("硬件外设");
        data3.setIcon(R.mipmap.icon_card_un_bind);
        data3.setSelect(false);

        data4.setTitle("版本更新");
        data4.setIcon(R.mipmap.icon_card_lost);
        data4.setSelect(false);

        mList.add(data);
        mList.add(data1);
        mList.add(data2);
        mList.add(data3);
        mList.add(data4);

    }
}
